
/**
\file
Definition of the nmn::console_log_handler class.
\author Sean Tromans
*/

#ifndef NMN_LOG_HANDLERS_CONSOLE_LOG_HANDLER_HPP
#define NMN_LOG_HANDLERS_CONSOLE_LOG_HANDLER_HPP

#include <needs_more_ninja/template/output_message.hpp>
#include <needs_more_ninja/template/log/logger.hpp>

namespace nmn
{

	/**
	A log handler to output logging information to the debug console.
	\author Sean Tromans
	*/
	template< typename char_t, typename traits_t = std::char_traits< char_t >, typename allocator_t = std::allocator< char_t > >
	class console_log_handler
	{
		//
		//	Public Member Types
		//
		public:

			typedef typename logger< char_t, traits_t, allocator_t > log_type;

		//
		//	Public Member Functions
		//
		public:

			/**
			Constructor
			@param use_unformatted Whether to output the unformatted message rather than the formatted version. Defaults to false.
			\author Sean Tromans
			*/
			console_log_handler( bool use_unformatted = false )
				:	use_unformatted( use_unformatted )
			{
			}

			/**
			Logger callback to output the formatted message to the debug console.
			@param message The unformatted raw message sent to the logger.
			@param formatted_message The formatted message created by the logger with additional information.
			\author Sean Tromans
			*/
			void operator( )( typename log_type::string_type const & message, typename log_type::string_type const & formatted_message )
			{
				if ( !use_unformatted )
				{
					nmn::output_message( formatted_message );
				}
				else
				{
					nmn::output_message( message );
				}
			}

		//
		//	Private Member Variables
		//
		private:

			bool use_unformatted;
	};

}

#endif	//NMN_LOG_HANDLERS_CONSOLE_LOG_HANDLER_HPP
